package cloud.maque.admin.controller;

import cloud.maque.admin.annotations.TenantId;
import cloud.maque.admin.annotations.TenantQuery;
import cloud.maque.admin.domain.entity.MqPrivilegeGroup;
import cloud.maque.admin.domain.vo.MqPrivilegeGroupVo;
import cloud.maque.admin.service.MqPrivilegeGroupService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 自定义权限接口
 *
 * @author zhuyf
 * @date 2023/3/17 20:57
 */
@RestController
@RequestMapping(value = "/privilege/group")
@Api(tags = "运维-自定义权限组接口")
public class PrivilegeGroupController {

    @Autowired
    MqPrivilegeGroupService privilegeGroupService;


    @PostMapping("/tree")
    @ApiOperation(value = "自定义权限树")
    @TenantQuery
    public ResponseBodyVo<List<MqPrivilegeGroupVo>> Tree(@RequestBody @ApiParam("查询内容") PaginateDataResquest<MqPrivilegeGroup> pageReq) {
        return ResponseBodyVo.Success(privilegeGroupService.Tree(pageReq));
    }

    @PostMapping("/list")
    @ApiOperation(value = "自定义权限列表")
    public ResponseBodyVo<List<MqPrivilegeGroup>> list(@RequestBody @ApiParam("查询内容") MqPrivilegeGroup pageReq) {
        return ResponseBodyVo.Success(privilegeGroupService.List(pageReq));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "自定义权限详情")
    public ResponseBodyVo<MqPrivilegeGroup> Detail(@RequestParam("id") String id) {
        return ResponseBodyVo.Success(privilegeGroupService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增组")
    public ResponseBodyVo<MqPrivilegeGroup> insert(@RequestBody @ApiParam("组内容") MqPrivilegeGroup group) {
        return ResponseBodyVo.Success(privilegeGroupService.saveGroup(group));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除组")
    @TenantQuery
    public ResponseBodyVo<Boolean> Delete(@PathVariable("id") String groupId, @TenantId String tenantId) {
        return ResponseBodyVo.Success(privilegeGroupService.delete(groupId,tenantId));
    }


}
